home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl5
- #
- # connect-end.cgi
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
- # $Id: connect-end.cgi,v 1.57 1997/06/19 22:26:42 shotes Exp $
-
- require "/usr/OnRamp/lib/OnRamp.pm";
-
- if (!$ARGV[0]) { printf("Location: %s%c%c","/tasks/Tasks.connect-start.cgi",10,10); }
-
- $myname = "connect-end.cgi?" . $ARGV[0];
- $temp = "task.tmp";
- $dummy = "task.dummy";
-
- $passwd = "/etc/passwd";
- $isdnop = "/etc/config/isdnd.options";
- $sendmail = "/etc/sendmail.params";
- $hosts = "/etc/hosts";
- $resolv = "/etc/resolv.conf";
- $ppp = "/etc/ppp.conf";
- $ppp_config = "/etc/config/ppp.startup";
- $modem_file = "/usr/OnRamp/etc/modem.trans";
- $devices = "/etc/uucp/Devices";
- $systems = "/etc/uucp/Systems";
- $confW = "/etc/config/wsyncd.options";
- $init = "/etc/inittab";
-
- $it = "<td colspan=60>";
- $ni = "</td>";
- $bo = "<td colspan=150><font size=5><i>";
- $nb = "</i></font></td>";
-
- &get_fields;
-
- if ($fld{'cancel'}) {
- $message = "Network configuration cancelled";
- } elsif ($fld{'accept'}) {
- &configure;
- #print "Location: /tasks/connect-epitath.cgi\n\n";
- $go = "/tasks/connect-epitath.cgi";
- print "Content-type: text/html\n\n";
- print "<HTML><HEAD>";
- print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$go\">";
- print "</HEAD><BODY></BODY></HTML>";
- exit 0;
- }
-
- &readValues;
-
- &generic;
-
- sub configure {
- &readValues;
-
- open(IN, "/usr/bsd/hostname |");
- $hostName = <IN>;
- close(IN);
- chop $hostName;
- if ($hostName =~ /^([^\.]*)\./) { $hostName = $1; }
- # ($name, $dummyb, $dummyc, $dummyd, @dummye) = gethostbyname($hostName);
- # $name =~ /^\w+\.(.*)$/;
- # $domainName = $1;
-
- $domainName = $terms{'domain'};
-
- # named
- if (-e "/usr/sbin/named") {
- open(IN,"/usr/OnRamp/bin/htnetwork | ");
- $line = <IN>;
- close(IN);
- @items = split(/:/,$line);
- $IPaddr = $items[3];
- @parts = split(/\./,$IPaddr);
- if ($parts[0] < 128) { # class A
- $rddan = $parts[0];
- $rddahni = "$parts[3].$parts[2].$parts[1]";
- }
- elsif ($parts[0] < 192) { # class B
- $rddan = "$parts[1].$parts[0]";
- $rddahni = "$parts[3].$parts[2]";
- }
- else { # class C
- $rddan = "$parts[2].$parts[1].$parts[0]";
- $rddahni = $parts[3];
- }
-
- @parts = split(/\./,$terms{'provider'});
- if ($parts[0] < 128) { # class A
- $rddahxe = "$parts[3].$parts[2].$parts[1]";
- }
- elsif ($parts[0] < 192) { # class B
- $rddahxe = "$parts[3].$parts[2]";
- }
- else { # class C
- $rddahxe = $parts[3];
- }
-
- $nmd{'localhost.rev'} = "/var/named";
- $nmd{'named.boot'} = "/etc";
- $nmd{'named.hosts'} = "/var/named";
- $nmd{'named.rev'} = "/var/named";
- foreach $arg (keys(%nmd)) {
- $fileIN = "/usr/OnRamp/etc/" . $arg;
- open(IN,"< $fileIN");
- open(OUT,"> $dummy");
- while(<IN>) {
- $_ =~ s/HOSTNAME/$hostName/g;
- $_ =~ s/DOMAIN/$domainName/g;
- $_ =~ s/RDDAN/$rddan/g;
- $_ =~ s/INADDR/$IPaddr/g;
- $_ =~ s/EXADDR/$terms{'provider'}/g;
- $_ =~ s/RDDAHNI/$rddahni/g;
- $_ =~ s/RDDAHXE/$rddahxe/g;
- $_ =~ s/NSADDR/$terms{'nameserver'}/g;
-
- print OUT $_;
- }
- close(IN);
- close(OUT);
- $fileOUT = $nmd{$arg} . "/" . $arg;
- rename($dummy,$fileOUT);
- }
- system("/etc/chkconfig", "named", "off");
- }
-
- # sendmail deamon
- open(OUT,"> $sendmail");
- print OUT "rootdomain:$domainName\n";
- print OUT "directdomains:$domainName\n";
- print OUT "forwarder:$terms{'mailserver'}\n";
- close(OUT);
-
- # /etc/ppp.conf
- $addLine = 1;
- $rename = 0;
- open(OUT,"> $dummy");
- open(IN,"< $ppp");
- while(<IN>) {
- @items = split(/\s+/);
- if ($items[0] eq 'ppp' && $items[1] eq 'add_route') {
- @subItems = split(/=/,$items[2]);
- if ($subItems[0] eq 'remotehost' &&
- $subItems[1] eq $terms{'provider'}) {
- $addLine = 0;
- print OUT $_;
- } else { $rename = 1; print OUT "# $_"; }
- } else { print OUT $_; }
- }
- close(IN);
- close(OUT);
- if ($rename) { rename($dummy,$ppp); }
-
- if ($addLine) {
- open(IN,"< $ppp");
- open(OUT,"> $dummy");
- $found = 0;
- while(<IN>) {
- $line = $_;
- @items = split(/\s+/,$line);
- if ($found == 0 && $items[1] eq 'Add' && $items[2] eq 'actual') {
- $found = 1;
- print OUT "$line\n";
- print OUT "ppp\t\tadd_route ";
- print OUT "remotehost=",$terms{'provider'},"\n\n";
- } else { print OUT $line; }
- }
- if (!$found) {
- print OUT "\nppp\t\tadd_route ";
- print OUT "remotehost=",$terms{'provider'},"\n";
- }
- close(IN);
- close(OUT);
- rename($dummy,$ppp);
- }
-
- # create ppp startup script
- if (! -e "/etc/init.d/pppstartup") {
- system("/sbin/cp", "/usr/WebFace/lib/S75pppstartup",
- "/etc/init.d/pppstartup");
- }
- if (! -l "/etc/rc2.d/S75pppstartup") {
- system("/sbin/ln", "-s", "/etc/init.d/pppstartup",
- "/etc/rc2.d/S75pppstartup");
- }
-
- if (-e $ppp_config) {
- $add = 1;
- open(IN, "< $ppp_config");
- while(<IN>) {
- if ($_ eq "ppp -r ppp\n") { $add = 0; }
- }
- close(IN);
- if ($add) {
- open(OUT,">> $ppp_config");
- print OUT "ppp -r ppp\n";
- close(OUT);
- }
- } else {
- open(OUT, "> $ppp_config");
- print OUT "# this file generated by gateway product\n";
- print OUT "# sh file read by /etc/init.d/pppstartup\n\n";
- print OUT "ppp -r ppp\n";
- close(OUT);
- }
-
- if (-e $ppp) { chmod 0600, $ppp; }
-
- # /etc/uucp/Systems
- if ($terms{'phone'}) {
- $phone = $terms{'phone'};
- $phone =~ s/-//g;
- $phone =~ s/\(//g;
- $phone =~ s/\)//g;
- }
- if ($terms{'hardware'} eq 'ISDN') {
- open(IN,"< $isdnop");
- open(OUT,"> $dummy");
- while(<IN>) {
- $line = $_;
- if (substr($_,0,2) ne "-t") { print OUT $_; }
- else { print OUT "# $line"; }
- }
- print OUT "-t $terms{'switchtype'}";
- if ($terms{'switchtype'} eq 'DMS100' || $terms{'switchtype'} eq 'NI1') {
- print OUT " -s $terms{'spid1'} -s $terms{'spid2'}";
- }
- print OUT "\n";
- close(OUT);
- close(IN);
- rename($dummy,$isdnop);
-
- system("/etc/chkconfig", "isdnd", "on");
-
- system("/bin/csh -c '(/bin/csh /etc/init.d/isdnd stop) >&! /dev/null'");
- system("/bin/csh -c '(/bin/csh /etc/init.d/isdnd start) >&! /dev/null'");
-
- $addLine = 1;
- $commentLine = 0;
- open(IN,"< $systems");
- while(<IN>) {
- @items = split(/\s+/);
- if ($items[0] eq 'ppp') {
- if (($items[6] eq 'ISDNCALL[56]' . $phone) ||
- ($items[6] eq 'ISDNCALL[64]' . $phone)) {
- $addLine = 0;
- } else {
- $commentLine = 1;
- }
- }
- }
- close(IN);
- if ($commentLine) {
- @lst = ('ppp','Any','ISDN');
- &comment($systems,*lst);
- }
- if ($addLine) {
- chmod 0600, $systems;
- open(OUT,">> $systems");
- if ($terms{'switchtype'} eq 'NET3') {
- print OUT
- qq|\nppp Any ISDN 38400 "" "" ISDNCALL[64]$phone CONNECTED\n|;
- } else {
- print OUT
- qq|\nppp Any ISDN 38400 "" "" ISDNCALL[56]$phone CONNECTED\n|;
- }
- close(OUT);
- chmod 0400, $systems;
- }
- } elsif ($terms{'hardware'} eq 'Modem') {
- $addLine = 1;
- $commentLine = 0;
- open(IN,"< $systems");
- while(<IN>) {
- @items = split(/\s+/);
- if ($items[0] eq 'ppp') {
- if ($items[3] eq $terms{'speed'} && $items[4] eq $phone) {
- $addLine = 0;
- } else {
- $commentLine = 1;
- }
- }
- }
- close(IN);
- if ($commentLine) {
- @lst = ('ppp','Any','ACU');
- &comment($systems,*lst);
- }
- if ($addLine) {
- chmod 0600, $systems;
- open(OUT,">> $systems");
- print OUT "\nppp Any ACU $terms{'speed'} $phone in:--in: ";
- print OUT "$terms{'lname'} word: $terms{'lpassword'}\n";
- close(OUT);
- chmod 0400, $systems;
- }
-
- } elsif ($terms{'hardware'} eq 'T1') {
- $addLine = 1;
- $commentLine = 0;
- open(IN,"< $systems");
- while(<IN>) {
- @items = split(/\s+/);
- if ($items[0] eq 'ppp') {
- if ($items[2] eq 'WAN') {
- $addLine = 0;
- } else {
- $commentLine = 1;
- }
- }
- }
- close(IN);
- if ($commentLine) {
- @lst = ('ppp','Any','WAN');
- &comment($systems,*lst);
- }
- if ($addLine) {
- chmod 0600, $systems;
- open(OUT,">> $systems");
- print OUT qq|ppp Any WAN - "" "" PPP CONNECTED\n|;
- close(OUT);
- chmod 0400, $systems;
- }
- }
-
- # /etc/uucp/Devices
- if ($terms{'hardware'} eq 'Modem') {
- if ($terms{'speed'} > 2400) { $port = "ttyf"; }
- else { $port = "ttym"; }
- if ($terms{'port'} eq 'Port 1') {
- $port .= "1"; $prt = "1";
- $dport = "ttyd1";
- } else {
- $port .= "2"; $prt = "2";
- $dport = "ttyd2";
- }
- $modem = &getModem($terms{'modem_type'});
- open(OUT,">> $devices");
- print OUT "ACU $port null $terms{'speed'} 212 x $modem\n";
- print OUT "Direct $dport - Any direct\n";
- close(OUT);
-
- $cmd = &hash_modem($terms{'modem_type'},1,3);
- if ($cmd) {
- $cmd = "/etc/uucp/" . "$cmd $prt";
- system("$cmd > /dev/null 2>&1");
- }
- } elsif ($terms{'hardware'} eq 'T1') {
- if ($terms{'port'} eq 'Port 1') { $dname = "/dev/gsc/wsty00"; }
- else { $dname = "/dev/gsc/wsty01"; }
- $rename = 0;
- $found = 0;
- open(IN,"< $devices");
- open(OUT,"> $dummy");
- while(<IN>) {
- @items = split(/\s+/);
- if ($items[0] ne 'WAN') { print OUT $_; next; }
- if ($items[1] ne $dname) {
- print OUT "# $_";
- $rename = 1;
- $found = 1;
- print OUT qq|WAN $dname - - direct\n|;
- } else { print OUT $_; $found = 1; }
- }
- if (!$found) {
- print OUT qq|WAN $dname - - direct\n|;
- $rename = 1;
- }
- close(IN);
- close(OUT);
- if ($rename) { rename($dummy,$devices); }
- }
-
- # /etc/inittab
- if ($terms{'hardware'} eq 'Modem') {
- $rename = 0;
- if ($terms{'port'} eq 'Port 1') { $port = 1; }
- else { $port = 2; }
- open(IN,"< $init");
- open(OUT,"> $dummy");
- while(<IN>) {
- @items = split(/:/);
- if ($items[0] ne "t".$port) { print OUT $_; next; }
- if ($items[2] ne "off") {
- $items[2] = "off";
- print OUT join(/:/,@items);
- $rename = 1;
- }
- }
- close(OUT);
- close(IN);
- if ($rename) { rename($dummy,$init); }
- }
-
- # /etc/resolv.conf
- open(OUT,"> $resolv");
- print OUT "search $domainName\n";
- print OUT "hostresorder nis bind local\n\n";
- print OUT "nameserver 0.0.0.0\n";
- print OUT "nameserver $terms{'nameserver'}\n";
- close(OUT);
-
- # T1
- if ($terms{'hardware'} eq 'T1') {
- if ($terms{'port'} eq 'Port 1') {
- &turnOffPort(1);
- &turnOnPort(0);
- } else {
- &turnOffPort(0);
- &turnOnPort(1);
- }
-
- system("/etc/chkconfig", "wsyncd", "on");
- } else {
- if (-e "/etc/config/wsyncd") {
- system("/etc/chkconfig", "wsyncd", "off");
- }
- }
-
- # ethernet (effects /etc/hosts and /etc/config/ifconfig-[n].options)
- if ($terms{'hardware'} eq 'Ethernet') {
- ($eth_type,$eth_label) = split(/ /,$terms{'interface'});
- open(IN,"/usr/OnRamp/bin/htnetwork | ");
- while(<IN>) {
- @items = split(/:/);
- if ($eth_type == $items[1]) {
- $oldIP = $items[3];
- $num = $items[0];
- }
- }
- close(IN);
- $num++;
- $file = "/etc/config/ifconfig-" . $num . ".options";
- open(OUT,"> $file");
- print OUT "netmask $terms{'netmask'}\n";
- close(OUT);
-
- open(IN,"hostname | ");
- $hostname = <IN>; chop($hostname);
- close(IN);
-
- if ($oldIP) { &removeHosts($oldIP); }
- &addHosts($terms{'address'},"gate-".$hostname.".".$terms{'domain'});
- system("/usr/etc/ifconfig", $eth_label, "inet", $terms{'address'},
- "netmask", $terms{'netmask'});
- }
-
- # tighten security
- &nofreepass;
- }
-
- sub nofreepass {
- $PASSSOURCEFILE = "/etc/passwd";
- $PASSWORKFILE = "/etc/passwd.tmp";
- open(PASSWORDS, $PASSSOURCEFILE );
- open(PASSOUT, ">$PASSWORKFILE");
-
- while (<PASSWORDS>) {
- split(/:/);
- $_[1] = '*' if !$_[1] && $_[0] ne 'root';
- print PASSOUT join(':' ,@_);
- }
-
- close(PASSOUT);
- close(PASSWORDS);
-
- rename($PASSWORKFILE,$PASSSOURCEFILE);
- unlink $PASSWORKFILE;
- }
-
- sub removeHosts {
- local($rem_ip) = $_[0];
- open(IN,"< $hosts");
- open(OUT,"> $dummy");
- while(<IN>) {
- if (/^#/) {
- print OUT $_;
- next;
- }
- if (/^$rem_ip/) {
- print OUT "# ".$_;
- next;
- }
- print OUT $_;
- }
- close(OUT);
- close(IN);
- rename($dummy, $hosts);
- }
-
- sub addHosts {
- local($add_ip) = $_[0];
- local($add_hs) = $_[1];
- open(OUT,">> $hosts");
- print OUT "$add_ip\t$addhs\n";
- close(OUT);
- }
-
- sub getModem {
- $ret = "";
- $key = $_[0];
- open(IN,"< $modem_file");
- while(<IN>) {
- @items = split(/:/);
- if ($key eq $items[1]) {
- $ret = $items[0];
- last;
- }
- }
- close(IN);
- return $ret;
- }
-
- sub readValues {
- open(IN,"< $temp");
- while(<IN>) {
- @items = split(/=/);
- chop $items[1];
- $terms{$items[0]} = $items[1];
- }
- close(IN);
- }
-
- sub generic {
- print "Content-type: text/html\n\n";
- print "<html><head><title>Summary</title>\n";
- print "<script language=\"JavaScript\">\n<!--\n";
-
- # JavaScript
- print "which = \"none\";
- function runSubmit() {
- if(which == \"accept\") return (true);
- if(which == \"cancel\") return runCancel();
- return (true);
- }
- function markAccept() { which = \"accept\"; }
- function markCancel() { which = \"cancel\"; }
- function runCancel() {
- setTimeout('window.location=\"/tasks/Tasks.connect-start.cgi?end\"',0);
- return (false);
- }
- function Previous() {
- form = document.end;
- if (form.prev.value == \"m\") { setTimeout('window.location=\"/tasks/connect-modem.cgi?end\"',0); }
- if (form.prev.value == \"i\") { setTimeout('window.location=\"/tasks/connect-isdn.cgi?end\"',0); }
- if (form.prev.value == \"t\") { setTimeout('window.location=\"/tasks/connect-t1.cgi?end\"',0); }
- if (form.prev.value == \"e\") { setTimeout('window.location=\"/tasks/connect-ether-fddi.cgi?end\"',0); }
- return;
- }\n";
-
- print "//-->\n";
- print "</script></head>\n\n";
-
- print "<body bgcolor='c7ded4' background=/tasks/connect-task.bg.gif>\n";
-
- print "<i>$message</i>";
-
-
- print "<table width=100%>",
- "<tr><th align=left><h1>Summary</h1></th>\n",
- "<th align=right><a href=\"/newsplash.shtml\">",
- "<img height=55 width=57 border=0 src=/tasks/home.gif></a>\n",
- " <a href=\"/tasks/Tasks.shtml\">",
- "<img height=55 width=57 border=0 src=/tasks/back.gif></a>",
- "</tr></table>\n";
-
- print "<br>
- Review the information that you entered in the Internet Gateway configuration
- forms:<br><br>\n\n";
-
- print "<center><table>\n";
-
- if ($terms{'hardware'} eq 'Ethernet or FDDI') {
- @items = split(/\s+/,$terms{'interface'});
- $outHardware = $items[0];
- $outInterface = $items[1];
- } else { $outHardware = $terms{'hardware'}; }
-
- print "<tr><td>Domain name:</td><td>$terms{'domain'}</td></tr>\n";
- print "<tr><td>Provider address:</td><td>$terms{'provider'}</td></tr>\n";
- print "<tr><td>Name server:</td><td>$terms{'nameserver'}</td></tr>\n";
- print "<tr><td>Mail forwarder:</td><td>$terms{'mailserver'}</td></tr>\n";
- print "<tr><td></td><td></td></tr>\n";
- print "<tr><td>Hardware:</td><td>$outHardware</td></tr>\n";
-
- if ($terms{'hardware'} eq 'Modem') {
- print "<tr><td>Port:</td><td>$terms{'port'}</td></tr>\n";
- print "<tr><td>Modem type:</td><td>$terms{'modem_type'}</td></tr>\n";
- print "<tr><td>Baud rate:</td><td>$terms{'speed'}</td></tr>\n";
- print "<tr><td>Phone number:</td><td>$terms{'phone'}</td></tr>\n";
- print "<tr><td>Login name:</td><td>$terms{'lname'}</td></tr>\n";
- print "<tr><td>Login password:</td><td>$terms{'lpassword'}</td></tr>\n";
- } elsif ($terms{'hardware'} eq 'ISDN') {
- if ($terms{'switchtype'} eq 'NET3') {
- print "<tr><td>Switch:</td><td>NET3/DSS1</td></tr>\n";
- } else {
- print "<tr><td>Switch:</td><td>$terms{'switchtype'}</td></tr>\n";
- }
- print "<tr><td>Phone number:</td><td>$terms{'phone'}</td></tr>\n";
- if ($terms{'switchtype'} eq 'DMS100' || $terms{'switchtype'} eq 'NI1') {
- print "<tr><td>SPID #1:</td><td>$terms{'spid1'}</td></tr>\n";
- print "<tr><td>SPID #2:</td><td>$terms{'spid2'}</td></tr>\n";
- }
- } elsif ($terms{'hardware'} eq 'T1') {
- print "<tr><td>Port:</td><td>$terms{'port'}</td></tr>\n";
- } elsif (substr($terms{'hardware'},0,6) eq 'Ethern') {
- print "<tr><td>Interface:</td><td>$outInterface</td></tr>\n";
- print "<tr><td>IP address:</td><td>$terms{'address'}</td></tr>\n";
- print "<tr><td>Netmask:</td><td>$terms{'netmask'}</td></tr>\n";
- }
-
- print "</table></center><br>\n\n";
-
- printf("<form name=\"end\" action=\"%s\" method=post onSubmit=\"return runSubmit()\">\n", $myname);
-
- print "<input type=hidden name=prev value=$ARGV[0]>\n";
-
- print "<table width=630>";
-
- print "<tr><td width=50%>If the summary information is correct, select <I>Accept and
- Reboot</I> to configure and reboot the WebForce Internet Gateway. The
- Gateway will take four or five minutes to reboot and restart its network
- services. If the information that you entered on the setup forms is
- correct, you will be able to access the Internet when this process
- is complete.
- </td>";
-
- print "<td align=right valign=top><font size=5><i>\n";
- print qq|<input type=submit name="accept" value="Accept"
- onClick="markAccept()">\n|;
- print "</i></font></td></tr>\n\n";
-
- print "<tr><td> </td></tr>\n";
-
- print "<tr><td>If you see an error in the summary information, select
- <I>Cancel</I> to delay the configuration and return to the first page
- of the Setup forms to correct your entries. Or, select <I>Previous</I>
- to return directly to the previous form.</td>";
-
- print "<td align=right valign=top><font size=5><i>\n";
- print qq|<input type=submit name="cancel" value="Cancel"
- onClick="markCancel()">\n|;
- print "</i></font></td></tr>\n\n";
-
- print "</table>\n";
-
- print '<MAP NAME="js_map1">',
- ' <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Previous()"
- onMouseOver="window.status=\'\';return true">',
- '</MAP>',
- '<IMG SRC="/tasks/leftarrow.gif" BORDER=0 USEMAP="#js_map1" ALIGN="right">';
-
- print "\n</form></body></html>";
- }
-
- sub turnOffPort {
- $nm = $_[0];
-
- undef @terms;
- $terms[0] = 'wan0'.$nm;
- if (&lookFor(0,$confW,*terms)) { &comment($confW,*terms); }
-
- $terms[0] = 'wstyd0'.$nm;
- if (&lookFor(0,$confW,*terms)) { &comment($confW,*terms); }
-
- $terms[0] = 'wstyd0'.$nm;
- $terms[1] = 'wan0'.$nm;
- if (&lookFor(0,$confW,*terms)) { &comment($confW,*terms); }
- }
-
- sub turnOnPort {
- $nm = $_[0];
-
- undef @terms;
- $terms[0] = 'wan0'.$nm;
- if (&lookFor(1,$confW,*terms)) { &uncomment($confW,*terms); }
- elsif (! &lookFor(0,$confW,*terms)) {
- &writeTop($confW,"wan0".$nm."\td\t\t/dev/gsc/wan0".$nm);
- }
-
- $terms[0] = 'wstyd0'.$nm;
- if (&lookFor(1,$confW,*terms)) { &uncomment($confW,*terms); }
- elsif (! &lookFor(0,$confW,*terms)) {
- &writeTop($confW,"wstyd0".$nm."\t\td\t/dev/gsc/wstyd0".$nm);
- }
-
- $terms[0] = 'wstyd0'.$nm;
- $terms[1] = 'wan0'.$nm;
- if (&lookFor(1,$confW,*terms)) { &uncomment($confW,*terms); }
- elsif (! &lookFor(0,$confW,*terms)) {
- if ($nm == 0) { $let = "D"; } else { $let = "E"; }
- &writeBottom($confW,"$terms[0]\t\t$terms[1]\tWSYNCD_SNID=$let");
- }
- }
-
- sub writeTop {
- local($file) = $_[0];
- local($value) = $_[1];
- $found = 0;
- open(IN,"< $file");
- open(OUT,"> $dummy");
- while(<IN>) {
- if ($_ eq "%%\n" && $found == 0) {
- $found = 1;
- print OUT "$value\n\n%%\n";
- }
- if ($_ eq "\n" && $found == 0) {
- $found = 1;
- print OUT "\n$value\n";
- } else { print OUT $_; }
- }
- close(IN);
- close(OUT);
- rename($dummy,$file);
- }
-
- sub writeBottom {
- local($file) = $_[0];
- local($value) = $_[1];
- $found = 0;
- open(IN,"< $file");
- open(OUT,"> $dummy");
- while(<IN>) {
- if (substr($_,0,2) eq '%%' && $found == 0) {
- print OUT "%%\n\n$value\n";
- $found = 1;
- } else { print OUT $_; }
- }
- if ($found == 0) { print OUT "$value\n"; }
- close(IN);
- close(OUT);
- rename($dummy,$file);
- }
-
- sub uncomment {
- local($file) = $_[0];
- local(*values) = @_[1];
-
- open(IN,"< $file");
- open(OUT,"> $dummy");
- $fix = "fix";
-
- while(<IN>) {
- $line = $_;
- if ($line eq "\n") { print OUT "\n"; next; }
- $fix =~ /(fix)/;
- $line =~ /^\s*\#\s*(\S.*)/;
- $line1 = $1;
- @items = split(/\s+/,$line1);
- $chk = 1;
- for ($ii=0;$ii<=$#values;$ii++) {
- if ($items[$ii] ne $values[$ii]) { $chk = 0; }
- }
- if ($chk) { print OUT "$line1\n"; }
- else { print OUT $line; }
- }
- close(OUT);
- close(IN);
- rename($dummy,$file);
- }
-
- sub comment {
- $ret = 0;
- local($file) = $_[0];
- local(*values) = @_[1];
-
- open(IN,"< $file");
- open(OUT,"> $dummy");
- while(<IN>) {
- $line = $_;
- if ($line eq "\n") { print OUT "\n"; next; }
- @items = split(/\s+/,$line);
- $chk = 1;
- for ($ii=0;$ii<=$#values;$ii++) {
- if ($items[$ii] ne $values[$ii]) { $chk = 0; }
- }
- if ($chk) { print OUT "#$line"; $ret = 1; }
- else { print OUT $line; }
- }
- close(OUT);
- close(IN);
- rename($dummy,$file);
- return $ret;
- }
-
- sub lookFor {
- local($ii);
- local($mode) = $_[0];
- local($file) = $_[1];
- local(*values) = @_[2];
- open(IN,"< $file");
- while(<IN>) {
- $line = $_;
- if ($mode == 1) {
- $line =~ /^\s*\#\s*(\S.*)/;
- $line1 = $1;
- } else { $line1 = $line; }
- @items = split(/\s+/,$line1);
- $chk = 1;
- for ($ii=0;$ii<=$#values;$ii++) {
- if ($items[$ii] ne $values[$ii]) { $chk = 0; }
- }
- if ($chk) { close(IN); return 1; }
- }
- close(IN);
- return 0;
- }
-